package com.yzc.util;

import java.util.List;

/**
 * 获取当前用户信息帮助类
 */
public class AuthContextHolder {

    private static final ThreadLocal<Long> userId = new ThreadLocal<>();
    private static final ThreadLocal<String> username = new ThreadLocal<>();
    private static final ThreadLocal<List<String>> roles = new ThreadLocal<>();
    private static final ThreadLocal<String> token = new ThreadLocal<>();

    public static void setUserId(Long _userId) {
        userId.set(_userId);
    }

    public static Long getUserId() {
        return userId.get();
    }

    public static void setUsername(String _username) {
        username.set(_username);
    }

    public static String getUsername() {
        return username.get();
    }

    public static void setRoles(List<String> _roles) {
        roles.set(_roles);
    }

    public static List<String> getRoles() {
        return roles.get();
    }

    public static void setToken(String _token) {
        token.set(_token);
    }

    public static String getToken() {
        return token.get();
    }


    public static void clear() {
        userId.remove();
        username.remove();
        roles.remove();
        token.remove();
    }
}
